<template>
  <div class="hotgoods">


    <div id="slider" class="mui-slider">
      <div id="sliderSegmentedControl"
           class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
        <div class="mui-scroll">
          <router-link class="mui-control-item-llb"
                       v-for="item in goodsGroupList"
                       :to="item.id + ''"
                       :key="item.id">
            {{item.name}}
          </router-link>
        </div>
      </div>
    </div>

    <router-view></router-view>

  </div>
</template>

<script>
  import mui from "../../lib/mui/js/mui.min"

  export default {
    name: 'HotGoods',
    data() {
      return {
        /*商品分组*/
        goodsGroupList: {id: 0, name: "所有单品"},
      }
    },
    methods: {
      /*获取商品分组*/
      getGoodsGroups() {
        //TODO 请求后台获取商品分类

        this.$http.get("/static/json_file/GoodsGroups.json").then(res => {
          res.body.unshift(this.goodsGroupList);
          this.goodsGroupList = res.body;
        });
      }
    },
    created() {
      this.getGoodsGroups();
    },
    mounted() {
      /*初始化scroll控件*/
      mui('.mui-scroll-wrapper').scroll({
        deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
      });
    }
  }
</script>

<style scoped>
  .mui-table-view .mui-media-object {
    line-height: 42px;
    max-width: 120px;
    height: 120px;
  }

  .mui-table-view h1 {
    font-size: 18px;
  }


  /*重写.mui-control-item类的样式为.mui-control-item-llb,mui.js中有.mui-control-item的点击事件,会根据路由点击冲突*/
  .mui-slider .mui-segmented-control.mui-segmented-control-inverted .mui-control-item-llb.mui-active {
    border-bottom: 0;
  }
  .mui-segmented-control.mui-segmented-control-inverted .mui-control-item-llb.mui-active {
    color: #007aff;
    border-bottom: 2px solid #007aff;
    background: none;
  }
  .mui-segmented-control.mui-segmented-control-inverted .mui-control-item-llb {
    color: inherit;
    border: 0;
  }
  .mui-segmented-control.mui-scroll-wrapper .mui-control-item-llb {
    display: inline-block;
    width: auto;
    padding: 0 20px;
    border: 0;
  }
  .mui-segmented-control .mui-control-item-llb {
    line-height: 38px;
    display: table-cell;
    overflow: hidden;
    width: 1%;
    -webkit-transition: background-color .1s linear;
    transition: background-color .1s linear;
    text-align: center;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #007aff;
    border-color: #007aff;
    border-left: 1px solid #007aff;
  }
</style>
